package com.axonactive.yolo.dto;

import com.axonactive.yolo.util.ConvertUnixTime;
import com.axonactive.yolo.util.Utils;

public class AirportArrival extends AirportDeparture {
	private String arrivalTime;
	private String arrivalTimeHHmmss;
	private String arrivalTimeDDmmYYYY;
	private DateTimeDescription arrivalTimeDescription;
	// this field is used for wego.
	private String localArrivalTime;

	public String getArrivalTime() {
		return arrivalTime;
	}

	public void setArrivalTime(String arrivalTime) {
		this.arrivalTimeDescription = new DateTimeDescription();
		this.arrivalTime = arrivalTime;
		if (this.localArrivalTime != null) {
			String monthString = this.localArrivalTime.substring(5, 7);
			String dateString = this.localArrivalTime.substring(8, 9);
			String yearString = this.localArrivalTime.substring(0, 4);
			String hourString = this.localArrivalTime.substring(11, 13);
			String minuteString = this.localArrivalTime.substring(14, 16);
			this.arrivalTimeDescription.setNAM(Utils.convertToInt(yearString));
			this.arrivalTimeDescription.setTHANG(Utils
					.convertToInt(monthString));
			this.arrivalTimeDescription.setNGAY(Utils.convertToInt(dateString));
			this.arrivalTimeDescription.setGIO(Utils.convertToInt(hourString));
			this.arrivalTimeDescription.setPHUT(Utils
					.convertToInt(minuteString));

		} else {

			arrivalTimeDescription = new DateTimeDescription();

			ConvertUnixTime convertUnixTime = new ConvertUnixTime();
			this.arrivalTimeDescription = convertUnixTime
					.getLocalTimeBaseOnJDK(this.arrivalTime);
		}
	}

	public String getArrivalTimeByDDMMYY() {
		if(arrivalTimeDescription==null){
			return "";
		}
		return arrivalTimeDescription.getNGAY() + "/"
				+ arrivalTimeDescription.getTHANG() + "/"
				+ arrivalTimeDescription.getNAM();
	}

	public String getArrivalTimeByHHmm() {
		if(arrivalTimeHHmmss!=null){
			return (arrivalTimeHHmmss.substring(0, 5));
		}
		if (arrivalTimeDescription == null) {
			return "";
		} else {
			String gio = Utils.formatNumber(arrivalTimeDescription.getGIO());
			String phut = Utils.formatNumber(arrivalTimeDescription.getPHUT());
			return gio + ":" + phut;
		}
	}

	// public void setArrivalTimeDescription() {
	// Calendar cal =
	// Utils.convertToDateTimeDescription(this.arrivalTime,this.code);
	// this.arrivalTimeDescription.setNAM(cal.get(Calendar.YEAR));
	// this.arrivalTimeDescription.setTHANG(cal.get(Calendar.MONTH)+1);
	// this.arrivalTimeDescription.setNGAY(cal.get(Calendar.DAY_OF_MONTH));
	// this.arrivalTimeDescription.setGIO(cal.get(Calendar.HOUR_OF_DAY));
	// this.arrivalTimeDescription.setPHUT(cal.get(Calendar.MINUTE));
	// }

	public void setLocalArrivalTime(String localArrivalTimeStr) {
		this.localArrivalTime = localArrivalTimeStr;
	}

	/**
	 * @return yyyy/MM/dd
	 */
	public String getArrivalTimeYYYYMMDD() {
		if(arrivalTimeDDmmYYYY!=null){
			String date = arrivalTimeDDmmYYYY.replaceAll("-", "/");
			return date;
		}
		if (arrivalTimeDescription == null) {
			return "";
		} else {
			String thang = Utils
					.formatNumber(arrivalTimeDescription.getTHANG());
			String ngay = Utils.formatNumber(arrivalTimeDescription.getNGAY());
			return arrivalTimeDescription.getNAM() + "/" + thang + "/" + ngay;
		}
	}

	/**
	 * @return the arrivalTimeHHmmss (20:00:00)
	 */
	public String getArrivalTimeHHmmss() {
		return arrivalTimeHHmmss;
	}

	/**
	 * @return the arrivalTimeDDmmYYYY (31-12-2014)
	 */ 
	public String getArrivalTimeDDmmYYYY() {
		return arrivalTimeDDmmYYYY;
	}

	/**
	 * @param arrivalTimeHHmmss the arrivalTimeHHmmss to set
	 */
	public void setArrivalTimeHHmmss(String arrivalTimeHHmmss) {
		this.arrivalTimeHHmmss = arrivalTimeHHmmss;
	}

	/**
	 * @param arrivalTimeDDmmYYYY the arrivalTimeDDmmYYYY to set
	 */
	public void setArrivalTimeDDmmYYYY(String arrivalTimeDDmmYYYY) {
		this.arrivalTimeDDmmYYYY = arrivalTimeDDmmYYYY;
	}
	

}
